package se.rkrantz.simpleraid.hibernate.dao.impl;

import java.util.List;

import org.joda.time.DateTime;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import se.rkrantz.simpleraid.hibernate.dao.RaidDao;
import se.rkrantz.simpleraid.hibernate.domain.Raid;

public class RaidDaoImpl extends HibernateDaoSupport implements RaidDao {

	@Override
	public void save(Raid raid) {
		getHibernateTemplate().save(raid);
	}

	@Override
	public void update(Raid raid) {
		getHibernateTemplate().update(raid);
	}

	@Override
	public void delete(Raid raid) {
		getHibernateTemplate().delete(raid);
	}

	@Override
	public Raid findRaidById(long raidId) {
		return (Raid) getHibernateTemplate().get(Raid.class, raidId);
	}

	@Override
	public List<Raid> getRaidsBetweenDates(DateTime start, DateTime end) {
		@SuppressWarnings("unchecked")
		List<Raid> list = getHibernateTemplate().find("from Raid r where r.raidDate >= ? and r.raidDate <= ?", start, end);
		return list;
	}

}
